package com.smart.controller;

import com.smart.common.WebResponse;
import com.smart.common.annotation.WebAccess;
import com.smart.common.PageInfo;
import com.smart.model.request.ProjectFileTaskAddRequest;
import com.smart.model.request.ProjectFileTaskRequest;
import com.smart.model.request.ProjectFileTaskUpdateRequest;
import com.smart.model.request.ProjectWeeklyTaskRequest;
import com.smart.model.vo.ProjectVO;
import com.smart.service.ProjectFileTaskService;
import com.smart.model.vo.ProjectFileTaskVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @author zhanghong
 */
@RestController
@RequestMapping("/fileTask")
@Api(value = "项目文件任务模块", tags = {"【监管端】项目文件任务模块"})
public class ProjectFileTaskController {

    @Autowired
    private ProjectFileTaskService projectFileTaskService;

    @WebAccess(login = true)
    @ApiOperation(value = "查看", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/get/{id}")
    public WebResponse<ProjectFileTaskVO> getByKey(HttpServletRequest request, @PathVariable("id") long id) {
        return WebResponse.build(projectFileTaskService.getByKey(id));
    }

    @WebAccess(login = true)
    @ApiOperation(value = "撤销", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/revoke/{id}")
    public WebResponse<Boolean> revokeById(HttpServletRequest request, @PathVariable("id") long id) {
        return WebResponse.build(projectFileTaskService.revokeById(id));
    }

    @WebAccess(login = true)
    @ApiOperation("文件下发分页查询")
    @PostMapping("/pageQuery")
    public WebResponse<PageInfo<ProjectFileTaskVO>> pageQuery(@RequestBody ProjectFileTaskRequest request) {
        return WebResponse.build(projectFileTaskService.pageQuery(request));
    }

    @WebAccess(login = true)
    @ApiOperation("【监管端】文件接收项目名单分页列表")
    @PostMapping("/project/pageQuery")
    public WebResponse<PageInfo<ProjectVO>> projectPageQuery(@RequestBody ProjectFileTaskRequest request) {
        return WebResponse.build(projectFileTaskService.projectPageQuery(request));
    }

    @WebAccess(login = true)
    @ApiOperation("新增")
    @PostMapping("/add")
    public WebResponse<Boolean> add(@Valid @RequestBody ProjectFileTaskAddRequest request) {
        return WebResponse.build(projectFileTaskService.add(request));
    }

    @WebAccess(login = true)
    @ApiOperation("修改")
    @PostMapping("/update")
    public WebResponse<Boolean> updateByKey(@Valid @RequestBody ProjectFileTaskUpdateRequest request) {
        return WebResponse.build(projectFileTaskService.updateByKey(request));
    }

    @WebAccess(login = true)
    @ApiOperation(value = "获取文件编号", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/getFileCode")
    public WebResponse<String> getFileCode() {
        return WebResponse.build(projectFileTaskService.getFileCode());
    }

}
